﻿CREATE FUNCTION [acms].[GetParentPath]
(
	@ParentId int
)
RETURNS Varchar
AS
BEGIN
	declare @tmp varchar(255) 
	select @tmp = isNull(b.ParentPath, '') + b.Name + '/'
	from [acms].[Posts] a
		inner join [acms].[PostVersions] b on a.Id = b.PostId
	where a.Id = @ParentId
	
	return @tmp
	/*declare @NewParentId int
	declare @Path varchar(2000)
	declare @Name varchar(100)
	
	select @NewParentId = ParentId, @Name = Name From PageVersions Where PostId = @ParentId
	
	if @NewParentId is not null
		set @Path = [acms].[GetParentPath](@NewParentId)
	else
		set @Path = ''
	
	return @Path + @Name + '/'*/
END